package csc.daonjpa.java.controller;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import csc.daonjpa.java.domain.Account;
import csc.daonjpa.java.domain.Transactions;
import csc.daonjpa.java.service.AccountService;
import csc.daonjpa.java.service.CustomerService;
import csc.daonjpa.java.service.TransactionService;

@Controller
public class TransactionController {
	private TransactionService transactionService;
	private CustomerService customerService;
	private AccountService accounService;
	
	
	public AccountService getAccounService() {
		return accounService;
	}
	@Autowired
	public void setAccounService(AccountService accounService) {
		this.accounService = accounService;
	}
	public CustomerService getCustomerService() {
		return customerService;
	}
	@Autowired
	public void setCustomerService(CustomerService customerService) {
		this.customerService = customerService;
	}
	public TransactionService getTransactionService() {
		return transactionService;
	}
	@Autowired
	public void setTransactionService(TransactionService transactionService) {
		this.transactionService = transactionService;
	}
	@RequestMapping(value = "/transactions")
	public String viewTransactions(HttpSession session, Model model) {
		
		String loginId = session.getAttribute("loginSession").toString();
		List<Account> lstAccount = accounService.getAccountByCustomer(loginId);
		ArrayList<List<Transactions>> arrayList = new ArrayList<List<Transactions>>(lstAccount.size());
		for (Account account : lstAccount) {
			List<Transactions> lst = transactionService.getTransactionByAccount(account.getNumber());
			if (lst != null) {
				arrayList.add(transactionService.getTransactionByAccount(account.getNumber()));
			}
		}
		model.addAttribute("arrayList", arrayList);
		return "transactions";
	}
	
}
